package com.approval.approvalapp.index;


import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.support.design.widget.AppBarLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.approval.approval.LocationService;
import com.approval.approvalapp.MainActivity;
import com.approval.approvalapp.MyAppliaction;
import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.IndexFragmentBean;
import com.approval.approvalapp.center.acitivty.ExceptionReviseActivity;
import com.approval.approvalapp.center.index.CenterIndexFragment;
import com.approval.approvalapp.center.index.SearchWebActivity;
import com.approval.approvalapp.index.cygn.hys.HysListActivity;
import com.approval.approvalapp.index.cygn.qjshenqing.QjShenqingActivity;
import com.approval.approvalapp.index.cygn.wzly.WzlyActivity;
import com.approval.approvalapp.index.cygn.xxbs.XxbsActivity;
import com.approval.approvalapp.index.cygn.yjcn.JyyjActivity;
import com.approval.approvalapp.index.dbsx.ptbl.PtBlActivity;
import com.approval.approvalapp.index.dbsx.qjsp.QjSpActivity;
import com.approval.approvalapp.index.dbsx.tshf.TsHfActivity;
import com.approval.approvalapp.index.dbsx.wsys.WsYsActivity;
import com.approval.approvalapp.index.dbsx.wzsp.activity.WzSpActivity;
import com.approval.approvalapp.index.dbsx.zxhf.ZxHfActivity;
import com.approval.approvalapp.message.MessageXqActivity;
import com.approval.approvalapp.myself.activity.WdkqActivity;
import com.approval.approvalapp.util.DensityUtil;
import com.approval.approvalapp.util.ErrorBeanUtil;
import com.approval.approvalapp.util.SpUtil;
import com.approval.approvalapp.util.base.BaseFragment;
import com.approval.approvalapp.util.net.NetRequsetUtil;
import com.approval.approvalapp.util.net.interfacepac.NetDownResponse;
import com.approval.approvalapp.util.view.MyMarkerView;
import com.approval.approvalapp.util.view.MyMarkerView2;
import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.Poi;
import com.bumptech.glide.Glide;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.MPPointF;
import com.google.gson.Gson;
import com.uuzuche.lib_zxing.activity.CaptureActivity;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * A simple {@link Fragment} subclass.
 */
public class IndexFragment extends BaseFragment implements AppBarLayout.OnOffsetChangedListener, View.OnClickListener {


    @Bind(R.id.titleTv1)
    TextView titleTv1;
    @Bind(R.id.titleTv2)
    TextView titleTv2;
    @Bind(R.id.grbj_tv)
    TextView grbjTv;
    @Bind(R.id.grbj_ll)
    LinearLayout grbjLl;
    @Bind(R.id.ckbj_tv)
    TextView ckbjTv;
    @Bind(R.id.ckbj_ll)
    LinearLayout ckbjLl;
    @Bind(R.id.bjtv)
    TextView bjtv;
    @Bind(R.id.dbj_tv)
    TextView dbjTv;
    @Bind(R.id.dbj_ll)
    LinearLayout dbjLl;
    @Bind(R.id.ycq_tv)
    TextView ycqTv;
    @Bind(R.id.ycq_ll)
    LinearLayout ycqLl;
    @Bind(R.id.kcq_tv)
    TextView kcqTv;
    @Bind(R.id.kcq_ll)
    LinearLayout kcqLl;
    @Bind(R.id.nametv)
    TextView nametv;
    @Bind(R.id.sbdktime_tv)
    TextView sbdktimeTv;
    @Bind(R.id.sbdktime_iv)
    ImageView sbdktimeIv;
    @Bind(R.id.sbdkll)
    LinearLayout sbdkll;
    @Bind(R.id.v)
    View v;
    @Bind(R.id.xbdktime_tv)
    TextView xbdktimeTv;
    @Bind(R.id.xbdktime_iv)
    ImageView xbdktimeIv;
    @Bind(R.id.more_infotv)
    TextView moreInfotv;
    @Bind(R.id.wsyx_iv)
    ImageView wsyxIv;
    @Bind(R.id.tip_wsystv)
    TextView tipWsystv;
    @Bind(R.id.wsys_rl)
    RelativeLayout wsysRl;
    @Bind(R.id.wsystv)
    TextView wsystv;
    @Bind(R.id.wsys_ll)
    LinearLayout wsysLl;
    @Bind(R.id.qjsp_iv)
    ImageView qjspIv;
    @Bind(R.id.tip_qjsptv)
    TextView tipQjsptv;
    @Bind(R.id.qjsp_rl)
    RelativeLayout qjspRl;
    @Bind(R.id.qjsptv)
    TextView qjsptv;
    @Bind(R.id.qjsp_ll)
    LinearLayout qjspLl;
    @Bind(R.id.zxhf_iv)
    ImageView zxhfIv;
    @Bind(R.id.tip_zxhftv)
    TextView tipZxhftv;
    @Bind(R.id.zxhf_rl)
    RelativeLayout zxhfRl;
    @Bind(R.id.zxhftv)
    TextView zxhftv;
    @Bind(R.id.zxhf_ll)
    LinearLayout zxhfLl;
    @Bind(R.id.ptbl_iv)
    ImageView ptblIv;
    @Bind(R.id.tip_ptbl)
    TextView tipPtbl;
    @Bind(R.id.ptbl_rl)
    RelativeLayout ptblRl;
    @Bind(R.id.ptbltv)
    TextView ptbltv;
    @Bind(R.id.ptbl_ll)
    LinearLayout ptblLl;
    @Bind(R.id.wzsp_iv)
    ImageView wzspIv;
    @Bind(R.id.tip_wzsptv)
    TextView tipWzsptv;
    @Bind(R.id.wzsp_rl)
    RelativeLayout wzspRl;
    @Bind(R.id.wzsptv)
    TextView wzsptv;
    @Bind(R.id.wzsp_ll)
    LinearLayout wzspLl;
    @Bind(R.id.tshf_iv)
    ImageView tshfIv;
    @Bind(R.id.tip_tshftv)
    TextView tipTshftv;
    @Bind(R.id.tshf_rl)
    RelativeLayout tshfRl;
    @Bind(R.id.tshftv)
    TextView tshftv;
    @Bind(R.id.tshf_ll)
    LinearLayout tshfLl;
    @Bind(R.id.qjsq_iv)
    ImageView qjsqIv;
    @Bind(R.id.qjsqtv)
    TextView qjsqtv;
    @Bind(R.id.qjsq_ll)
    LinearLayout qjsqLl;
    @Bind(R.id.wzly_iv)
    ImageView wzlyIv;
    @Bind(R.id.wzlytv)
    TextView wzlytv;
    @Bind(R.id.wzly_ll)
    LinearLayout wzlyLl;
    @Bind(R.id.hyssq_iv)
    ImageView hyssqIv;
    @Bind(R.id.hyssqtv)
    TextView hyssqtv;
    @Bind(R.id.hyssq_ll)
    LinearLayout hyssqLl;
    @Bind(R.id.jyyj_iv)
    ImageView jyyjIv;
    @Bind(R.id.jyyjtv)
    TextView jyyjtv;
    @Bind(R.id.jyyj_ll)
    LinearLayout jyyjLl;
    @Bind(R.id.xxbs_iv)
    ImageView xxbsIv;
    @Bind(R.id.xxbstv)
    TextView xxbstv;
    @Bind(R.id.xxbs_ll)
    LinearLayout xxbsLl;
    @Bind(R.id.ydjxpm_tv)
    TextView ydjxpmTv;
    @Bind(R.id.wssjbll_tv)
    TextView wssjbllTv;
    @Bind(R.id.bllzs_tv)
    TextView bllzsTv;
    @Bind(R.id.message_root)
    LinearLayout message_root;
    @Bind(R.id.swipeRefreshLayout)
    SwipeRefreshLayout swipeRefreshLayout;
    @Bind(R.id.xroot)
    LinearLayout xroot;
    @Bind(R.id.toolbar)
    Toolbar toolbar;

    protected String[] mParties = new String[]{
            "好评", "中评", "差评"
    };

    public static final int[] VORDIPLOM_COLORS1 = {
            Color.parseColor("#4071FF"), Color.parseColor("#F8AF35"), Color.parseColor("#DE463A")
    };
    @Bind(R.id.root)
    LinearLayout root;
    @Bind(R.id.erro_rl)
    RelativeLayout erroRl;
    @Bind(R.id.kqtj_tv1)
    TextView kqtjTv1;
    @Bind(R.id.kqtj_numtv1)
    TextView kqtjNumtv1;
    @Bind(R.id.kqtj_ll1)
    LinearLayout kqtjLl1;
    @Bind(R.id.kqtj_tv2)
    TextView kqtjTv2;
    @Bind(R.id.kqtj_numtv2)
    TextView kqtjNumtv2;
    @Bind(R.id.kqtj_ll2)
    LinearLayout kqtjLl2;
    @Bind(R.id.kqtj_tv3)
    TextView kqtjTv3;
    @Bind(R.id.kqtj_numtv3)
    TextView kqtjNumtv3;
    @Bind(R.id.kqtj_ll3)
    LinearLayout kqtjLl3;
    @Bind(R.id.kqtj_tv4)
    TextView kqtjTv4;
    @Bind(R.id.kqtj_numtv4)
    TextView kqtjNumtv4;
    @Bind(R.id.kqtj_ll4)
    LinearLayout kqtjLl4;
    @Bind(R.id.kqtj_tv5)
    TextView kqtjTv5;
    @Bind(R.id.kqtj_numtv5)
    TextView kqtjNumtv5;
    @Bind(R.id.kqtj_ll5)
    LinearLayout kqtjLl5;
    @Bind(R.id.kqtj_tv6)
    TextView kqtjTv6;
    @Bind(R.id.kqtj_numtv6)
    TextView kqtjNumtv6;
    @Bind(R.id.kqtj_ll6)
    LinearLayout kqtjLl6;
    @Bind(R.id.more_message)
    ImageView moreMessage;
    @Bind(R.id.piecolortv)
    TextView piecolortv;
    @Bind(R.id.pjmctv)
    TextView pjmctv;
    @Bind(R.id.pjnumtv)
    TextView pjnumtv;
    @Bind(R.id.llhor1)
    LinearLayout llhor1;
    @Bind(R.id.llhor2)
    LinearLayout llhor2;
    @Bind(R.id.llhor3)
    LinearLayout llhor3;
    @Bind(R.id.llhor4)
    LinearLayout llhor4;
    @Bind(R.id.ptbl_view)
    View ptbl_view;
    @Bind(R.id.tshf_view)
    View tshf_view;
    @Bind(R.id.tv_comment_type)
    TextView tvCommentType;
    @Bind(R.id.tv_comment_num)
    TextView tvCommentNum;
    @Bind(R.id.tv_comment_pertype)
    TextView tvCommentPertype;
    @Bind(R.id.tv_comment_per)
    TextView tvCommentPer;
    @Bind(R.id.civ)
    CircleImageView civ;
    @Bind(R.id.by_ll)
    RelativeLayout by_ll;
    @Bind(R.id.cardport2)
    ImageView cardport2;
    @Bind(R.id.ycxz_iv)
    ImageView ycxzIv;
    @Bind(R.id.tip_ycxztv)
    TextView tipYcxztv;
    @Bind(R.id.ycxz_rl)
    RelativeLayout ycxzRl;
    @Bind(R.id.ycxztv)
    TextView ycxztv;
    @Bind(R.id.qddk_iv)
    ImageView qddk_iv;
    @Bind(R.id.ycxz_ll)
    LinearLayout ycxz_ll;
    @Bind(R.id.ycxzview)
    View ycxzview;
    @Bind(R.id.spbl_view)
    View spbl_view;
    @Bind(R.id.search_iv)
    ImageView search_iv;
    @Bind(R.id.zx_iv)
    ImageView zx_iv;


    private PieChart pieChart;
    private LineChart lineChart;
    private IndexFragmentBean indexFragmentBean;
    private Boolean isInCk = false;//当前状态是点击窗口还是个人
    private View mView;
    private List<IndexFragmentBean.FbsBean> fbs;
    private List<String> handle;
    private List<String> speed;
    @Bind(R.id.custom_text_tv)
    TextView custom_text_tv;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_index;
    }

    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        if (verticalOffset == 0) {
            swipeRefreshLayout.setEnabled(true);
            toolbar.setVisibility(View.GONE);
        } else if (verticalOffset == -appBarLayout.getHeight()) {
            toolbar.setVisibility(View.VISIBLE);
        } else {
            swipeRefreshLayout.setEnabled(false);
        }

    }

    @Override
    public void initView(View view) {
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = this.getActivity().getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            this.getActivity().getWindow().setStatusBarColor(Color.TRANSPARENT);
        }

        Log.d("IndexFragmSSent", SpUtil.getString(this.getActivity(), SpUtil.USER_RUN_ID, ""));

        Glide.with(this.getActivity()).load(SpUtil.getString(this.getActivity(), SpUtil.USER_AVATER, ""))
                .into(civ);

        mView = view;
        titleTv2.setText(SpUtil.getString(MyAppliaction.getInstance(), SpUtil.UNIT_NAME, ""));
        titleTv1.setText(SpUtil.getString(MyAppliaction.getInstance(), SpUtil.USER_RUN_NICKNAME, ""));
        initPieChart(view);
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                requestData();
            }
        });

        // TODO: 2019/5/7 隐藏 2是窗口工作人员 3：首席代表  1：中心人员
        if (SpUtil.getString(this.getActivity(), SpUtil.Usertype, "").equals("2")) {
            qjspLl.setVisibility(View.GONE);
            wzspLl.setVisibility(View.GONE);
            ptbl_view.setVisibility(View.GONE);
            tshf_view.setVisibility(View.VISIBLE);
            spbl_view.setVisibility(View.VISIBLE);
            ycxz_ll.setVisibility(View.INVISIBLE);
            ycxzview.setVisibility(View.GONE);


        } else if (SpUtil.getString(this.getActivity(), SpUtil.Usertype, "").equals("3")) {
            ptblLl.setVisibility(View.GONE);
            wsysLl.setVisibility(View.GONE);
            ptbl_view.setVisibility(View.VISIBLE);
            tshf_view.setVisibility(View.VISIBLE);
            spbl_view.setVisibility(View.GONE);
            ycxz_ll.setVisibility(View.VISIBLE);
            ycxzview.setVisibility(View.VISIBLE);
        }
    }


    @Override
    public void initData() {
        swipeRefreshLayout.setRefreshing(true);
        root.setVisibility(View.GONE);

        String string = SpUtil.getString(IndexFragment.this.getActivity(), SpUtil.INDEXCACHE, "");
        if (!TextUtils.isEmpty(string)) {
            root.setVisibility(View.VISIBLE);
            indexFragmentBean = JSON.parseObject(string, IndexFragmentBean.class);
            //饼图
            isInCk = false;
//                piecolortv.setText("");
//                pjmctv.setText("");
//                pjnumtv.setText("");
            piecolortv.setText(indexFragmentBean.getGr().getGr_hp().getPer() + "");
            pjmctv.setText("好评");
            piecolortv.setTextColor(Color.parseColor("#4071FF"));
            pjnumtv.setText(indexFragmentBean.getGr().getGr_hp().getNum() + "件");

            tvCommentType.setText("好评数");
            tvCommentPertype.setText("好评率");
            tvCommentNum.setText(indexFragmentBean.getGr().getGr_hp().getNum() + "");
            tvCommentPer.setText(indexFragmentBean.getGr().getGr_hp().getPer() + "");
            tvCommentPer.setTextColor(Color.parseColor("#4071FF"));


            grbjLl.setBackgroundColor(Color.parseColor("#1076FF"));
            grbjTv.setTextColor(Color.parseColor("#ffffff"));
            ckbjLl.setBackgroundColor(Color.parseColor("#FFF5F5F5"));
            ckbjTv.setTextColor(Color.parseColor("#FF7D8198"));
            setPieDataGr(indexFragmentBean.getGr());

            //办件预警
            dbjTv.setText(IndexFragment.this.indexFragmentBean.getWait_piece() + "");
            ycqTv.setText(IndexFragment.this.indexFragmentBean.getQuit_piece() + "");
            kcqTv.setText(IndexFragment.this.indexFragmentBean.getEnd_piece() + "");

            //今日考勤
            if (!TextUtils.isEmpty(IndexFragment.this.indexFragmentBean.getKq().getMorning())) {
                sbdktimeTv.setVisibility(View.VISIBLE);
                sbdktimeTv.setText(IndexFragment.this.indexFragmentBean.getKq().getMorning());
            } else {
                sbdktimeTv.setVisibility(View.GONE);
            }
            if (!TextUtils.isEmpty(IndexFragment.this.indexFragmentBean.getKq().getNight())) {
                xbdktimeTv.setVisibility(View.VISIBLE);
                xbdktimeTv.setText(IndexFragment.this.indexFragmentBean.getKq().getNight());
            } else {
                xbdktimeTv.setVisibility(View.GONE);
            }


            //近半月考勤统计
            List<IndexFragmentBean.KqTjBean> kq_tj = IndexFragment.this.indexFragmentBean.getKq_tj();
            IndexFragmentBean.KqTjBean kqTjBean = kq_tj.get(0);
            kqtjLl1.setVisibility(View.VISIBLE);
            kqtjNumtv1.setText(kqTjBean.getNum() + "");
            kqtjTv1.setText(kqTjBean.getName());


            try {
                IndexFragmentBean.KqTjBean kqTjBean2 = kq_tj.get(1);
                kqtjLl2.setVisibility(View.VISIBLE);
                kqtjNumtv2.setText(kqTjBean2.getNum() + "");
                kqtjTv2.setText(kqTjBean2.getName());
            } catch (Exception e) {
                kqtjLl2.setVisibility(View.INVISIBLE);
            }


            try {
                IndexFragmentBean.KqTjBean kqTjBean3 = kq_tj.get(2);
                kqtjLl3.setVisibility(View.VISIBLE);
                kqtjNumtv3.setText(kqTjBean3.getNum() + "");
                kqtjTv3.setText(kqTjBean3.getName());
            } catch (Exception e) {
                kqtjLl3.setVisibility(View.INVISIBLE);
            }

            try {
                IndexFragmentBean.KqTjBean kqTjBean4 = kq_tj.get(3);
                kqtjLl4.setVisibility(View.VISIBLE);
                kqtjNumtv4.setText(kqTjBean4.getNum() + "");
                kqtjTv4.setText(kqTjBean4.getName());
            } catch (Exception e) {
                kqtjTv4.setVisibility(View.INVISIBLE);
            }

            try {
                IndexFragmentBean.KqTjBean kqTjBean5 = kq_tj.get(4);
                kqtjLl5.setVisibility(View.VISIBLE);
                kqtjNumtv5.setText(kqTjBean5.getNum() + "");
                kqtjTv5.setText(kqTjBean5.getName());
            } catch (Exception e) {
                kqtjTv5.setVisibility(View.INVISIBLE);
            }

            try {
                IndexFragmentBean.KqTjBean kqTjBean6 = kq_tj.get(5);
                kqtjLl6.setVisibility(View.VISIBLE);
                kqtjNumtv6.setText(kqTjBean6.getNum() + "");
                kqtjTv6.setText(kqTjBean6.getName());
            } catch (Exception e) {
                kqtjTv6.setVisibility(View.INVISIBLE);
            }

            //通知
            if (indexFragmentBean.getNotice().getTitle() == null) {
                message_root.setVisibility(View.GONE);
            } else {
                message_root.setVisibility(View.VISIBLE);
                moreInfotv.setText(indexFragmentBean.getNotice().getTitle());
            }

            //6宫格红点
            if (indexFragmentBean.getWsys_num() != 0) {
                wsysRl.setVisibility(View.VISIBLE);
                if (indexFragmentBean.getWsys_num() < 99) {
                    tipWsystv.setText(indexFragmentBean.getWsys_num() + "");
                } else {
                    tipWsystv.setText("99");
                }
            } else {
                wsysRl.setVisibility(View.GONE);
            }

            if (indexFragmentBean.getQjsp_num() != 0) {
                qjspRl.setVisibility(View.VISIBLE);
                if (indexFragmentBean.getQjsp_num() < 99) {
                    tipQjsptv.setText(indexFragmentBean.getQjsp_num() + "");
                } else {
                    tipQjsptv.setText("99");
                }
            } else {
                qjspRl.setVisibility(View.GONE);
            }

            if (indexFragmentBean.getZxhf_num() != 0) {
                zxhfRl.setVisibility(View.VISIBLE);
                if (indexFragmentBean.getZxhf_num() < 99) {
                    tipZxhftv.setText(indexFragmentBean.getZxhf_num() + "");
                } else {
                    tipZxhftv.setText("99");
                }
            } else {
                zxhfRl.setVisibility(View.GONE);
            }

            if (indexFragmentBean.getPtbl_num() != 0) {
                ptblRl.setVisibility(View.VISIBLE);
                if (indexFragmentBean.getPtbl_num() < 99) {
                    tipPtbl.setText(indexFragmentBean.getPtbl_num() + "");
                } else {
                    tipPtbl.setText("99");
                }
            } else {
                ptblRl.setVisibility(View.GONE);
            }


            if (indexFragmentBean.getWzsp_num() != 0) {
                wzspRl.setVisibility(View.VISIBLE);
                if (indexFragmentBean.getWzsp_num() < 99) {
                    tipWzsptv.setText(indexFragmentBean.getWzsp_num() + "");
                } else {
                    tipWzsptv.setText("99");
                }
            } else {
                wzspRl.setVisibility(View.GONE);
            }


            if (indexFragmentBean.getTshf_num() != 0) {
                tshfRl.setVisibility(View.VISIBLE);
                if (indexFragmentBean.getTshf_num() < 99) {
                    tipTshftv.setText(indexFragmentBean.getTshf_num() + "");
                } else {
                    tipTshftv.setText("99");
                }
            } else {
                tshfRl.setVisibility(View.GONE);
            }

            // TODO: 2019/5/24   异常修正红点
            if (indexFragmentBean.getYcxz_num() != 0) {
                ycxzRl.setVisibility(View.VISIBLE);
                if (indexFragmentBean.getYcxz_num() < 99) {
                    tipYcxztv.setText(indexFragmentBean.getYcxz_num() + "");
                } else {
                    tipYcxztv.setText("99");
                }
            } else {
                ycxzRl.setVisibility(View.GONE);
            }


            //折线图设置数据
            ydjxpmTv.setTextColor(Color.parseColor("#ffffff"));
            ydjxpmTv.setBackgroundColor(Color.parseColor("#1076FF"));
            wssjbllTv.setTextColor(Color.parseColor("#7D8198"));
            wssjbllTv.setBackgroundColor(Color.parseColor("#FFFAFAFA"));
            bllzsTv.setTextColor(Color.parseColor("#7D8198"));
            bllzsTv.setBackgroundColor(Color.parseColor("#FFFAFAFA"));
            List<Integer> rank = indexFragmentBean.getRank();
            initLineChart(mView, rank);
            setLineData1(rank);

            //9 + x
            fbs = indexFragmentBean.getFbs();

            xroot.removeAllViews();
            if (fbs != null && fbs.size() > 0) {
                int max;
                List<Integer> intlist = new ArrayList<>();
                for (int i = 0; i < fbs.size(); i++) {
                    fbs.get(i).getNum();
                    intlist.add(fbs.get(i).getNum());
                }
                max = Collections.max(intlist);
                intlist.clear();
                for (int i = 0; i < fbs.size(); i++) {
                    View view = LayoutInflater.from(IndexFragment.this.getActivity()).inflate(R.layout.item_xx, xroot, false);
                    final TextView textView = view.findViewById(R.id.tv);
                    textView.setText(fbs.get(i).getTitle());
                    TextView xzxk_tv = view.findViewById(R.id.xzxk_tv);
                    xzxk_tv.setText(fbs.get(i).getNum() + "");
                    View blue_view = view.findViewById(R.id.blue_view);
                    View gray_view = view.findViewById(R.id.gray_view);
                    DensityUtil.changeViewSizeWidthWithView(gray_view, blue_view, (float) fbs.get(i).getNum() / max);
                    view.setOnClickListener(IndexFragment.this);
                    xroot.addView(view);
                }
            }
        }


        swipeRefreshLayout.postDelayed(new Runnable() {
            @Override
            public void run() {

                requestData();
            }
        }, 1000);
    }

    int zxtstate = 0;

    private void getLocation() {

        if (ActivityCompat.checkSelfPermission(this.getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this.getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (location != null) {
            double latitude = location.getLatitude();
            double longitude = location.getLongitude();
            String lstr = latitude + "";
            String longtr = longitude + "";
            String latitudestr = lstr.substring(0, 5);
            String longitudestr = longtr.substring(0, 6);

            Intent intent = new Intent(IndexFragment.this.getActivity(), QdActivity.class);
            intent.putExtra("latitudestr", latitudestr);
            intent.putExtra("longitudestr", longitudestr);
            startActivity(intent);


        } else {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, locationListener);
        }

    }

    LocationListener locationListener = new LocationListener() {
        // Provider的状态在可用、暂时不可用和无服务三个状态直接切换时触发此函数
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            Log.d("MainActivity", "1");
        }

        // Provider被enable时触发此函数，比如GPS被打开
        @Override
        public void onProviderEnabled(String provider) {
            Log.d("MainActivity", "1");
        }

        // Provider被disable时触发此函数，比如GPS被关闭
        @Override
        public void onProviderDisabled(String provider) {
            Log.d("MainActivity", "1");

        }

        // 当坐标改变时触发此函数，如果Provider传进相同的坐标，它就不会被触发
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
                Log.e("Map", "Location changed : Lat: " + location.getLatitude() + " Lng: " + location.getLongitude());
                double latitude = location.getLatitude();
                double longitude = location.getLongitude();
                String lstr = latitude + "";
                String longtr = longitude + "";
                String latitudestr = lstr.substring(0, 5);
                String longitudestr = longtr.substring(0, 6);

                Intent intent = new Intent(IndexFragment.this.getActivity(), QdActivity.class);
                intent.putExtra("latitudestr", latitudestr);
                intent.putExtra("longitudestr", longitudestr);
                startActivity(intent);

            } else {
                Log.d("MainActivity", "gg");
            }
        }
    };

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 500:
                //处理扫描结果（在界面上显示）
                if (null != data) {
                    Bundle bundle = data.getExtras();
                    if (bundle == null) {
                        return;
                    }
                    if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) {
                        String result = bundle.getString(CodeUtils.RESULT_STRING);
                        String gwid = result.substring((result.lastIndexOf("=") + 1), result.length());
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("GWID", gwid);
//                        v1/center/sao_hui_yi_login
                        NetRequsetUtil.getInstance().netRequestPostJson("v1/center/sao_hui_yi_login",
                                jsonObject.toString(), new NetDownResponse() {
                                    @Override
                                    public void success(String str) {
                                        Toast.makeText(IndexFragment.this.getActivity(), "签到成功", Toast.LENGTH_SHORT).show();
                                    }

                                    @Override
                                    public void errowithresponse(String str) {
                                        ErrorBeanUtil.getErrorMessage(str);
                                    }

                                    @Override
                                    public void erro() {

                                    }

                                    @Override
                                    public void finish() {

                                    }
                                });
                    } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) {
                        Toast.makeText(IndexFragment.this.getActivity(), "解析二维码失败", Toast.LENGTH_LONG).show();
                    }
                }
                break;
            case 100:
                if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                    //gps已打开
//                    getLocation();
                    locationService.start();// 定位SDK

                } else {
                    Intent i = new Intent();
                    i.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    startActivityForResult(i, 100);
                }
                break;
        }
    }

    private LocationManager locationManager;

    private LocationService locationService;


    @OnClick({R.id.grbj_ll, R.id.ckbj_ll, R.id.ydjxpm_tv, R.id.wssjbll_tv, R.id.bllzs_tv, R.id.erro_rl, R.id.qjsp_ll, R.id.qjsq_ll
            , R.id.wzsp_ll, R.id.zxhf_ll, R.id.wsys_ll, R.id.ptbl_ll, R.id.tshf_ll, R.id.xxbs_ll,
            R.id.jyyj_ll, R.id.message_root, R.id.wzly_ll, R.id.hyssq_ll, R.id.by_ll, R.id.qddk_iv, R.id.ycxz_ll,
            R.id.search_iv, R.id.zx_iv})
    public void onViewClicked(View view) {
        Intent intent = new Intent();
        switch (view.getId()) {
            case R.id.search_iv:
                intent.setClass(IndexFragment.this.getActivity(), SearchWebActivity.class);
                IndexFragment.this.startActivity(intent);
                break;
            case R.id.zx_iv:
                intent.setClass(IndexFragment.this.getActivity(), CaptureActivity.class);
                startActivityForResult(intent, 500);
                break;
            case R.id.ycxz_ll:
                intent.setClass(this.getActivity(), ExceptionReviseActivity.class);
                intent.putExtra("is_select", "2");
                this.getActivity().startActivity(intent);
                break;
            case R.id.qddk_iv:
                locationManager = (LocationManager) this.getActivity().getSystemService(Context.LOCATION_SERVICE);
                if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//                    getLocation();
                    //gps已打开
                    locationService.start();// 定位SDK
                } else {
                    Intent i = new Intent();
                    i.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    startActivityForResult(i, 100);
                }

                break;
            case R.id.by_ll:
                intent.setClass(this.getActivity(), WdkqActivity.class);
                startActivity(intent);
                break;
            case R.id.grbj_ll:
                isInCk = false;
                grbjLl.setBackgroundColor(Color.parseColor("#1076FF"));
                grbjTv.setTextColor(Color.parseColor("#ffffff"));
                ckbjLl.setBackgroundColor(Color.parseColor("#FFF5F5F5"));
                ckbjTv.setTextColor(Color.parseColor("#FF7D8198"));

                piecolortv.setText(indexFragmentBean.getGr().getGr_hp().getPer() + "");
                pjmctv.setText("好评");
                piecolortv.setTextColor(Color.parseColor("#4071FF"));
                pjnumtv.setText(indexFragmentBean.getGr().getGr_hp().getNum() + "件");

                tvCommentType.setText("好评数");
                tvCommentPertype.setText("好评率");
                tvCommentNum.setText(indexFragmentBean.getGr().getGr_hp().getNum() + "");
                tvCommentPer.setText(indexFragmentBean.getGr().getGr_hp().getPer() + "");
                tvCommentPer.setTextColor(Color.parseColor("#4071FF"));

                setPieDataGr(indexFragmentBean.getGr());
                break;
            case R.id.ckbj_ll:
                isInCk = true;
                ckbjLl.setBackgroundColor(Color.parseColor("#1076FF"));
                ckbjTv.setTextColor(Color.parseColor("#ffffff"));
                grbjLl.setBackgroundColor(Color.parseColor("#FFF5F5F5"));
                grbjTv.setTextColor(Color.parseColor("#FF7D8198"));
//                piecolortv.setText("");
//                pjmctv.setText("");
//                pjnumtv.setText("");
                piecolortv.setText(indexFragmentBean.getCk().getCk_hp().getPer() + "");
                pjmctv.setText("好评");
                piecolortv.setTextColor(Color.parseColor("#4071FF"));
                pjnumtv.setText(indexFragmentBean.getCk().getCk_hp().getNum() + "件");

                tvCommentType.setText("好评数");
                tvCommentPertype.setText("好评率");
                tvCommentNum.setText(indexFragmentBean.getCk().getCk_hp().getNum() + "");
                tvCommentPer.setText(indexFragmentBean.getCk().getCk_hp().getPer() + "");
                tvCommentPer.setTextColor(Color.parseColor("#4071FF"));

                setPieDataCk(indexFragmentBean.getCk());
                break;
            case R.id.ydjxpm_tv:
                zxtstate = 0;
                ydjxpmTv.setTextColor(Color.parseColor("#ffffff"));
                ydjxpmTv.setBackgroundColor(Color.parseColor("#1076FF"));
                wssjbllTv.setTextColor(Color.parseColor("#7D8198"));
                wssjbllTv.setBackgroundColor(Color.parseColor("#FFFAFAFA"));
                bllzsTv.setTextColor(Color.parseColor("#7D8198"));
                bllzsTv.setBackgroundColor(Color.parseColor("#FFFAFAFA"));
                List<Integer> rank = indexFragmentBean.getRank();
                initLineChart(mView, rank);
                setLineData1(rank);
                break;
            case R.id.wssjbll_tv:
                ydjxpmTv.setTextColor(Color.parseColor("#7D8198"));
                ydjxpmTv.setBackgroundColor(Color.parseColor("#FFFAFAFA"));
                wssjbllTv.setTextColor(Color.parseColor("#ffffff"));
                wssjbllTv.setBackgroundColor(Color.parseColor("#1076FF"));
                bllzsTv.setTextColor(Color.parseColor("#7D8198"));
                bllzsTv.setBackgroundColor(Color.parseColor("#FFFAFAFA"));
                handle = indexFragmentBean.getHandle();
                initLineChart2(mView);
                setLineData2(handle);
                break;
            case R.id.bllzs_tv:
                ydjxpmTv.setTextColor(Color.parseColor("#7D8198"));
                ydjxpmTv.setBackgroundColor(Color.parseColor("#FFFAFAFA"));
                wssjbllTv.setTextColor(Color.parseColor("#7D8198"));
                wssjbllTv.setBackgroundColor(Color.parseColor("#FFFAFAFA"));
                bllzsTv.setTextColor(Color.parseColor("#ffffff"));
                bllzsTv.setBackgroundColor(Color.parseColor("#1076FF"));
                speed = indexFragmentBean.getSpeed();
                initLineChart3(mView);
                setLineData3(speed);
                break;
            case R.id.erro_rl:
                requestData();
                break;
            case R.id.qjsp_ll:
                intent.setClass(this.getActivity(), QjSpActivity.class);
                startActivity(intent);
                break;
            case R.id.qjsq_ll:
                intent.setClass(this.getActivity(), QjShenqingActivity.class);
                startActivity(intent);
                break;
            case R.id.wzsp_ll:
                intent.setClass(this.getActivity(), WzSpActivity.class);
                startActivity(intent);
                break;

            case R.id.zxhf_ll:
                intent.setClass(this.getActivity(), ZxHfActivity.class);
                startActivity(intent);
                break;
            case R.id.wsys_ll:
                intent.setClass(this.getActivity(), WsYsActivity.class);
                startActivity(intent);
                break;
            case R.id.ptbl_ll:
                intent.setClass(this.getActivity(), PtBlActivity.class);
                startActivity(intent);
                break;
            case R.id.tshf_ll:
                intent.setClass(this.getActivity(), TsHfActivity.class);
                startActivity(intent);
                break;
            case R.id.xxbs_ll:
                intent.setClass(this.getActivity(), XxbsActivity.class);
                startActivity(intent);
                break;
            case R.id.jyyj_ll:
                intent.setClass(this.getActivity(), JyyjActivity.class);
                startActivity(intent);
                break;
            case R.id.message_root:
                intent.setClass(this.getActivity(), MessageXqActivity.class);
                if (indexFragmentBean != null) {
                    intent.putExtra("bean", indexFragmentBean.getNotice());
                    intent.putExtra("from", "2,3");
                    startActivity(intent);
                }
                break;
            case R.id.wzly_ll:
                intent.setClass(this.getActivity(), WzlyActivity.class);
                startActivity(intent);
                break;
            case R.id.hyssq_ll:
                intent.setClass(this.getActivity(), HysListActivity.class);
                startActivity(intent);
                break;
        }
    }

    public void requestData() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("org_code", SpUtil.getString(MyAppliaction.getInstance(), SpUtil.ORG_CODE, "-1"));
        jsonObject.put("region_code", SpUtil.getString(MyAppliaction.getInstance(), SpUtil.REGION_CODE, "-1"));
        jsonObject.put("f_orgcode", SpUtil.getString(MyAppliaction.getInstance(), SpUtil.F_orgcode, "-1"));
        jsonObject.put("f_userid", SpUtil.getString(MyAppliaction.getInstance(), SpUtil.F_userid, "-1"));
        jsonObject.put("username", SpUtil.getString(MyAppliaction.getInstance(), SpUtil.USER_NAME, "-1"));
        jsonObject.put("f_orgname", SpUtil.getString(MyAppliaction.getInstance(), SpUtil.F_orgname, "-1"));
        jsonObject.put("name", SpUtil.getString(MyAppliaction.getInstance(), SpUtil.USER_RUN_NICKNAME, "-1"));
        jsonObject.put("orgename", SpUtil.getString(MyAppliaction.getInstance(), SpUtil.orgename, ""));
        Log.d("IndexFrassgment", jsonObject.toString());
        NetRequsetUtil.getInstance().netRequestPostJson("v1/user/app_index", jsonObject.toString(), new NetDownResponse() {
            @Override
            public void success(String str) {
                Log.d("IndexFragmentss", str);
                root.setVisibility(View.VISIBLE);
                erroRl.setVisibility(View.GONE);
                indexFragmentBean = JSON.parseObject(str, IndexFragmentBean.class);
                Gson gson = new Gson();
                String s = gson.toJson(indexFragmentBean);
                SpUtil.saveString(IndexFragment.this.getActivity(), SpUtil.INDEXCACHE, s);
                //饼图
                isInCk = false;
//                piecolortv.setText("");
//                pjmctv.setText("");
//                pjnumtv.setText("");
                piecolortv.setText(indexFragmentBean.getGr().getGr_hp().getPer() + "");
                pjmctv.setText("好评");
                piecolortv.setTextColor(Color.parseColor("#4071FF"));
                pjnumtv.setText(indexFragmentBean.getGr().getGr_hp().getNum() + "件");

                tvCommentType.setText("好评数");
                tvCommentPertype.setText("好评率");
                tvCommentNum.setText(indexFragmentBean.getGr().getGr_hp().getNum() + "");
                tvCommentPer.setText(indexFragmentBean.getGr().getGr_hp().getPer() + "");
                tvCommentPer.setTextColor(Color.parseColor("#4071FF"));


                grbjLl.setBackgroundColor(Color.parseColor("#1076FF"));
                grbjTv.setTextColor(Color.parseColor("#ffffff"));
                ckbjLl.setBackgroundColor(Color.parseColor("#FFF5F5F5"));
                ckbjTv.setTextColor(Color.parseColor("#FF7D8198"));
                setPieDataGr(indexFragmentBean.getGr());

                //办件预警
                dbjTv.setText(IndexFragment.this.indexFragmentBean.getWait_piece() + "");
                ycqTv.setText(IndexFragment.this.indexFragmentBean.getQuit_piece() + "");
                kcqTv.setText(IndexFragment.this.indexFragmentBean.getEnd_piece() + "");

                //今日考勤
                if (!TextUtils.isEmpty(IndexFragment.this.indexFragmentBean.getKq().getMorning())) {
                    sbdktimeTv.setVisibility(View.VISIBLE);
                    sbdktimeTv.setText(IndexFragment.this.indexFragmentBean.getKq().getMorning());
                } else {
                    sbdktimeTv.setVisibility(View.GONE);
                }
                if (!TextUtils.isEmpty(IndexFragment.this.indexFragmentBean.getKq().getNight())) {
                    xbdktimeTv.setVisibility(View.VISIBLE);
                    xbdktimeTv.setText(IndexFragment.this.indexFragmentBean.getKq().getNight());
                } else {
                    xbdktimeTv.setVisibility(View.GONE);
                }


                //近半月考勤统计
                List<IndexFragmentBean.KqTjBean> kq_tj = IndexFragment.this.indexFragmentBean.getKq_tj();
                IndexFragmentBean.KqTjBean kqTjBean = kq_tj.get(0);
                kqtjLl1.setVisibility(View.VISIBLE);
                kqtjNumtv1.setText(kqTjBean.getNum() + "");
                kqtjTv1.setText(kqTjBean.getName());


                try {
                    IndexFragmentBean.KqTjBean kqTjBean2 = kq_tj.get(1);
                    kqtjLl2.setVisibility(View.VISIBLE);
                    kqtjNumtv2.setText(kqTjBean2.getNum() + "");
                    kqtjTv2.setText(kqTjBean2.getName());
                } catch (Exception e) {
                    kqtjLl2.setVisibility(View.INVISIBLE);
                }


                try {
                    IndexFragmentBean.KqTjBean kqTjBean3 = kq_tj.get(2);
                    kqtjLl3.setVisibility(View.VISIBLE);
                    kqtjNumtv3.setText(kqTjBean3.getNum() + "");
                    kqtjTv3.setText(kqTjBean3.getName());
                } catch (Exception e) {
                    kqtjLl3.setVisibility(View.INVISIBLE);
                }

                try {
                    IndexFragmentBean.KqTjBean kqTjBean4 = kq_tj.get(3);
                    kqtjLl4.setVisibility(View.VISIBLE);
                    kqtjNumtv4.setText(kqTjBean4.getNum() + "");
                    kqtjTv4.setText(kqTjBean4.getName());
                } catch (Exception e) {
                    kqtjTv4.setVisibility(View.INVISIBLE);
                }

                try {
                    IndexFragmentBean.KqTjBean kqTjBean5 = kq_tj.get(4);
                    kqtjLl5.setVisibility(View.VISIBLE);
                    kqtjNumtv5.setText(kqTjBean5.getNum() + "");
                    kqtjTv5.setText(kqTjBean5.getName());
                } catch (Exception e) {
                    kqtjTv5.setVisibility(View.INVISIBLE);
                }

                try {
                    IndexFragmentBean.KqTjBean kqTjBean6 = kq_tj.get(5);
                    kqtjLl6.setVisibility(View.VISIBLE);
                    kqtjNumtv6.setText(kqTjBean6.getNum() + "");
                    kqtjTv6.setText(kqTjBean6.getName());
                } catch (Exception e) {
                    kqtjTv6.setVisibility(View.INVISIBLE);
                }

                //通知
                if (indexFragmentBean.getNotice().getTitle() == null) {
                    message_root.setVisibility(View.GONE);
                } else {
                    message_root.setVisibility(View.VISIBLE);
                    moreInfotv.setText(indexFragmentBean.getNotice().getTitle());
                }

                //6宫格红点
                if (indexFragmentBean.getWsys_num() != 0) {
                    wsysRl.setVisibility(View.VISIBLE);
                    if (indexFragmentBean.getWsys_num() < 99) {
                        tipWsystv.setText(indexFragmentBean.getWsys_num() + "");
                    } else {
                        tipWsystv.setText("99");
                    }
                } else {
                    wsysRl.setVisibility(View.GONE);
                }

                if (indexFragmentBean.getQjsp_num() != 0) {
                    qjspRl.setVisibility(View.VISIBLE);
                    if (indexFragmentBean.getQjsp_num() < 99) {
                        tipQjsptv.setText(indexFragmentBean.getQjsp_num() + "");
                    } else {
                        tipQjsptv.setText("99");
                    }
                } else {
                    qjspRl.setVisibility(View.GONE);
                }

                if (indexFragmentBean.getZxhf_num() != 0) {
                    zxhfRl.setVisibility(View.VISIBLE);
                    if (indexFragmentBean.getZxhf_num() < 99) {
                        tipZxhftv.setText(indexFragmentBean.getZxhf_num() + "");
                    } else {
                        tipZxhftv.setText("99");
                    }
                } else {
                    zxhfRl.setVisibility(View.GONE);
                }

                if (indexFragmentBean.getPtbl_num() != 0) {
                    ptblRl.setVisibility(View.VISIBLE);
                    if (indexFragmentBean.getPtbl_num() < 99) {
                        tipPtbl.setText(indexFragmentBean.getPtbl_num() + "");
                    } else {
                        tipPtbl.setText("99");
                    }
                } else {
                    ptblRl.setVisibility(View.GONE);
                }


                if (indexFragmentBean.getWzsp_num() != 0) {
                    wzspRl.setVisibility(View.VISIBLE);
                    if (indexFragmentBean.getWzsp_num() < 99) {
                        tipWzsptv.setText(indexFragmentBean.getWzsp_num() + "");
                    } else {
                        tipWzsptv.setText("99");
                    }
                } else {
                    wzspRl.setVisibility(View.GONE);
                }


                if (indexFragmentBean.getTshf_num() != 0) {
                    tshfRl.setVisibility(View.VISIBLE);
                    if (indexFragmentBean.getTshf_num() < 99) {
                        tipTshftv.setText(indexFragmentBean.getTshf_num() + "");
                    } else {
                        tipTshftv.setText("99");
                    }
                } else {
                    tshfRl.setVisibility(View.GONE);
                }

                //折线图设置数据
                ydjxpmTv.setTextColor(Color.parseColor("#ffffff"));
                ydjxpmTv.setBackgroundColor(Color.parseColor("#1076FF"));
                wssjbllTv.setTextColor(Color.parseColor("#7D8198"));
                wssjbllTv.setBackgroundColor(Color.parseColor("#FFFAFAFA"));
                bllzsTv.setTextColor(Color.parseColor("#7D8198"));
                bllzsTv.setBackgroundColor(Color.parseColor("#FFFAFAFA"));
                List<Integer> rank = indexFragmentBean.getRank();
                initLineChart(mView, rank);
                setLineData1(rank);

                //9 + x
                fbs = indexFragmentBean.getFbs();

                xroot.removeAllViews();
                if (fbs != null && fbs.size() > 0) {
                    int max;
                    List<Integer> intlist = new ArrayList<>();
                    for (int i = 0; i < fbs.size(); i++) {
                        fbs.get(i).getNum();
                        intlist.add(fbs.get(i).getNum());
                    }
                    max = Collections.max(intlist);
                    intlist.clear();
                    for (int i = 0; i < fbs.size(); i++) {
                        View view = LayoutInflater.from(IndexFragment.this.getActivity()).inflate(R.layout.item_xx, xroot, false);
                        TextView textView = view.findViewById(R.id.tv);
                        textView.setText(fbs.get(i).getTitle());
                        TextView xzxk_tv = view.findViewById(R.id.xzxk_tv);
                        xzxk_tv.setText(fbs.get(i).getNum() + "");
                        View blue_view = view.findViewById(R.id.blue_view);
                        View gray_view = view.findViewById(R.id.gray_view);
                        DensityUtil.changeViewSizeWidthWithView(gray_view, blue_view, (float) fbs.get(i).getNum() / max);
                        view.setOnClickListener(IndexFragment.this);
                        xroot.addView(view);
                    }

                    custom_text_tv.setText(indexFragmentBean.getCustom_text());
                }


            }

            @Override
            public void errowithresponse(String str) {
                erroRl.setVisibility(View.VISIBLE);
            }

            @Override
            public void erro() {
                if (erroRl != null) {
                    if (swipeRefreshLayout != null) {
                        swipeRefreshLayout.setRefreshing(false);
                    }
                    erroRl.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void finish() {
                if (swipeRefreshLayout != null) {
                    swipeRefreshLayout.setRefreshing(false);
                }
            }
        });
    }


    private void initPieChart(View view) {
        pieChart = view.findViewById(R.id.pieChart);
        pieChart.setUsePercentValues(true);
        pieChart.getDescription().setEnabled(false);
        pieChart.setExtraOffsets(0, 0, 0, 0);
        pieChart.setCenterText("");//中间的文字
        pieChart.setDrawHoleEnabled(true);//中间的洞
        pieChart.setHoleColor(Color.WHITE);
        pieChart.setTransparentCircleColor(Color.WHITE);
        pieChart.setTransparentCircleAlpha(110);
        pieChart.setHoleRadius(78f);
        pieChart.setTransparentCircleRadius(61f);
        pieChart.setDrawCenterText(true);//是否显示中间文字
        pieChart.setRotationAngle(0);
        pieChart.setDrawSliceText(false);//是否显示文字
        pieChart.setRotationEnabled(true);
        pieChart.setHighlightPerTapEnabled(true);
        pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
            @Override
            public void onValueSelected(Entry e, Highlight h) {
                Log.d("MainActivity12", "h:" + h);

                int x = (int) h.getX();

                if (isInCk) {
                    //窗口
                    if (x == 0) {
                        piecolortv.setText(indexFragmentBean.getCk().getCk_hp().getPer() + "");
                        pjmctv.setText("好评");
                        piecolortv.setTextColor(Color.parseColor("#4071FF"));
                        pjnumtv.setText(indexFragmentBean.getCk().getCk_hp().getNum() + "件");

                        tvCommentType.setText("好评数");
                        tvCommentPertype.setText("好评率");
                        tvCommentNum.setText(indexFragmentBean.getCk().getCk_hp().getNum() + "");
                        tvCommentPer.setText(indexFragmentBean.getCk().getCk_hp().getPer() + "");
                        tvCommentPer.setTextColor(Color.parseColor("#4071FF"));

                    } else if (x == 1) {
                        piecolortv.setText(indexFragmentBean.getCk().getCk_zp().getPer() + "");
                        pjmctv.setText("中评");
                        piecolortv.setTextColor(Color.parseColor("#F8AF35"));
                        pjnumtv.setText(indexFragmentBean.getCk().getCk_zp().getNum() + "件");

                        tvCommentType.setText("中评数");
                        tvCommentPertype.setText("中评率");
                        tvCommentNum.setText(indexFragmentBean.getCk().getCk_zp().getNum() + "");
                        tvCommentPer.setText(indexFragmentBean.getCk().getCk_zp().getPer() + "");
                        tvCommentPer.setTextColor(Color.parseColor("#F8AF35"));
                    } else {
                        piecolortv.setText(indexFragmentBean.getCk().getCk_cp().getPer() + "");
                        pjmctv.setText("差评");
                        piecolortv.setTextColor(Color.parseColor("#DE463A"));
                        pjnumtv.setText(indexFragmentBean.getCk().getCk_cp().getNum() + "件");

                        tvCommentType.setText("差评数");
                        tvCommentPertype.setText("差评率");
                        tvCommentNum.setText(indexFragmentBean.getCk().getCk_cp().getNum() + "");
                        tvCommentPer.setText(indexFragmentBean.getCk().getCk_cp().getPer() + "");
                        tvCommentPer.setTextColor(Color.parseColor("#DE463A"));
                    }
                } else {
                    //个人
                    if (x == 0) {
                        piecolortv.setText(indexFragmentBean.getGr().getGr_hp().getPer() + "");
                        pjmctv.setText("好评");
                        piecolortv.setTextColor(Color.parseColor("#4071FF"));
                        pjnumtv.setText(indexFragmentBean.getGr().getGr_hp().getNum() + "件");

                        tvCommentType.setText("好评数");
                        tvCommentPertype.setText("好评率");
                        tvCommentNum.setText(indexFragmentBean.getGr().getGr_hp().getNum() + "");
                        tvCommentPer.setText(indexFragmentBean.getGr().getGr_hp().getPer() + "");
                        tvCommentPer.setTextColor(Color.parseColor("#4071FF"));

                    } else if (x == 1) {
                        piecolortv.setText(indexFragmentBean.getGr().getGr_zp().getPer() + "");
                        pjmctv.setText("中评");
                        piecolortv.setTextColor(Color.parseColor("#F8AF35"));
                        pjnumtv.setText(indexFragmentBean.getGr().getGr_zp().getNum() + "件");

                        tvCommentType.setText("中评数");
                        tvCommentPertype.setText("中评率");
                        tvCommentNum.setText(indexFragmentBean.getGr().getGr_zp().getNum() + "");
                        tvCommentPer.setText(indexFragmentBean.getGr().getGr_zp().getPer() + "");
                        tvCommentPer.setTextColor(Color.parseColor("#F8AF35"));
                    } else {
                        piecolortv.setText(indexFragmentBean.getGr().getGr_cp().getPer() + "");
                        pjmctv.setText("差评");
                        piecolortv.setTextColor(Color.parseColor("#DE463A"));
                        pjnumtv.setText(indexFragmentBean.getGr().getGr_cp().getNum() + "件");

                        tvCommentType.setText("差评数");
                        tvCommentPertype.setText("差评率");
                        tvCommentNum.setText(indexFragmentBean.getGr().getGr_cp().getNum() + "");
                        tvCommentPer.setText(indexFragmentBean.getGr().getGr_cp().getPer() + "");
                        tvCommentPer.setTextColor(Color.parseColor("#DE463A"));
                    }
                }
            }

            @Override
            public void onNothingSelected() {

            }
        });
        Legend legend = pieChart.getLegend();
        legend.setEnabled(false);
    }

    private void initLineChart(View view, List<Integer> rank) {
        lineChart = view.findViewById(R.id.lineChart);
        lineChart.getDescription().setEnabled(false);
        lineChart.setPinchZoom(false);
        lineChart.setDrawGridBackground(false);
        lineChart.getAxisRight().setEnabled(false);

        XAxis xAxis = lineChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setDrawGridLines(false);

        xAxis.setLabelCount(rank.size(), true);

        xAxis.setValueFormatter(new ValueFormatter() {
            @Override
            public String getFormattedValue(float value) {
                return String.valueOf((int) value + 1).concat("月");
            }
        });

        YAxis leftAxis = lineChart.getAxisLeft();
        leftAxis.setValueFormatter(new ValueFormatter() {
            @Override
            public String getFormattedValue(float value) {
                BigDecimal b = new BigDecimal(value);
                value = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
                return String.valueOf(value).concat("");
            }
        });

        int max = Collections.max(rank);

        Log.d("max", "max:" + max);
        leftAxis.setAxisMaximum((max + 1));
//        leftAxis.setAxisMinimum(0f);

        lineChart.getAxisLeft().setDrawGridLines(false);

        lineChart.getLegend().setEnabled(false);

        MyMarkerView mv = new MyMarkerView(this.getActivity(), R.layout.custom_marker_view);
        mv.setChartView(lineChart); // For bounds control
        lineChart.setMarker(mv);
    }

    private void initLineChart2(View view) {
        lineChart = view.findViewById(R.id.lineChart);
        lineChart.getDescription().setEnabled(false);
        lineChart.setPinchZoom(false);
        lineChart.setDrawGridBackground(false);
        lineChart.getAxisRight().setEnabled(false);

        XAxis xAxis = lineChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setDrawGridLines(false);

        xAxis.setLabelCount(handle.size(), true);

        xAxis.setValueFormatter(new ValueFormatter() {
            @Override
            public String getFormattedValue(float value) {
                return String.valueOf((int) value + 1).concat("月");
            }
        });

        YAxis leftAxis = lineChart.getAxisLeft();
        leftAxis.setValueFormatter(new ValueFormatter() {
            @Override
            public String getFormattedValue(float value) {
                BigDecimal b = new BigDecimal(value);
                value = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
                return String.valueOf(value).concat("%");
            }
        });
        leftAxis.setLabelCount(5);
        leftAxis.setAxisMaximum(100f);
//        leftAxis.setAxisMinimum(0f);


        lineChart.getAxisLeft().setDrawGridLines(false);

        lineChart.getLegend().setEnabled(false);

        MyMarkerView2 mv = new MyMarkerView2(this.getActivity(), R.layout.custom_marker_view);
        mv.setChartView(lineChart); // For bounds control
        lineChart.setMarker(mv);
    }

    private void initLineChart3(View view) {
        lineChart = view.findViewById(R.id.lineChart);
        lineChart.getDescription().setEnabled(false);
        lineChart.setPinchZoom(false);
        lineChart.setDrawGridBackground(false);
        lineChart.getAxisRight().setEnabled(false);

        XAxis xAxis = lineChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setDrawGridLines(false);

        xAxis.setLabelCount(speed.size(), true);

        xAxis.setValueFormatter(new ValueFormatter() {
            @Override
            public String getFormattedValue(float value) {
                return String.valueOf((int) value + 1).concat("月");
            }
        });

        YAxis leftAxis = lineChart.getAxisLeft();
        leftAxis.setValueFormatter(new ValueFormatter() {
            @Override
            public String getFormattedValue(float value) {
                BigDecimal b = new BigDecimal(value);
                value = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
                return String.valueOf(value).concat("%");
            }
        });
        leftAxis.setLabelCount(5);
        leftAxis.setAxisMaximum(100f);
//        leftAxis.setAxisMinimum(0f);


        lineChart.getAxisLeft().setDrawGridLines(false);

        lineChart.getLegend().setEnabled(false);

        MyMarkerView2 mv = new MyMarkerView2(this.getActivity(), R.layout.custom_marker_view);
        mv.setChartView(lineChart); // For bounds control
        lineChart.setMarker(mv);
    }

    private void setPieDataGr(IndexFragmentBean.GrBean grBeanList) {

        ArrayList<PieEntry> entries = new ArrayList<PieEntry>();

        // NOTE: The order of the entries when being added to the entries array determines their position around the center of
        // the chart.

        entries.add(new PieEntry((float) (Integer.valueOf(grBeanList.getGr_hp().getNum())),
                mParties[0],
                getResources().getDrawable(R.drawable.star)));

//        entries.add(new PieEntry((float) (Integer.valueOf(grBeanList.getGr_zp().getNum())),
//                mParties[1],
//                getResources().getDrawable(R.drawable.star)));
//
//        entries.add(new PieEntry((float) (Integer.valueOf(grBeanList.getGr_cp().getNum())),
//                mParties[2],
//                getResources().getDrawable(R.drawable.star)));

        if ( Integer.valueOf(Integer.valueOf(grBeanList.getGr_zp().getNum())) == 0){
            entries.add(new PieEntry((float) (0),
                    mParties[1],
                    getResources().getDrawable(R.drawable.star)));
        }

        if (Integer.valueOf(Integer.valueOf(grBeanList.getGr_zp().getNum())) < 100 &&
                Integer.valueOf(Integer.valueOf(grBeanList.getGr_zp().getNum())) > 0) {
            entries.add(new PieEntry((float) (100),
                    mParties[1],
                    getResources().getDrawable(R.drawable.star)));
        }


        if (Integer.valueOf(Integer.valueOf(grBeanList.getGr_zp().getNum())) >= 100) {
            entries.add(new PieEntry((float) (Integer.valueOf(grBeanList.getGr_zp().getNum())),
                    mParties[1],
                    getResources().getDrawable(R.drawable.star)));
        }

        if (Integer.valueOf(Integer.valueOf(grBeanList.getGr_cp().getNum())) == 0) {
            entries.add(new PieEntry((float) (0),
                    mParties[2],
                    getResources().getDrawable(R.drawable.star)));
        }

        if (Integer.valueOf(Integer.valueOf(grBeanList.getGr_cp().getNum())) < 100
                && Integer.valueOf(grBeanList.getGr_cp().getNum()) > 0) {
            entries.add(new PieEntry((float) (100),
                    mParties[2],
                    getResources().getDrawable(R.drawable.star)));
        }

        if (Integer.valueOf(Integer.valueOf(grBeanList.getGr_cp().getNum())) >= 100) {
            entries.add(new PieEntry((float) (Integer.valueOf(grBeanList.getGr_cp().getNum())),
                    mParties[2],
                    getResources().getDrawable(R.drawable.star)));
        }


        PieDataSet dataSet = new PieDataSet(entries, "");

        dataSet.setDrawIcons(false);

        dataSet.setSliceSpace(3f);
        dataSet.setIconsOffset(new MPPointF(0, 40));
        dataSet.setSelectionShift(5f);

        ArrayList<Integer> colors = new ArrayList<Integer>();

        for (int c : VORDIPLOM_COLORS1)
            colors.add(c);

        dataSet.setColors(colors);
        PieData data = new PieData(dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(11f);
        data.setValueTextColor(Color.WHITE);
        pieChart.setData(data);
        pieChart.highlightValues(null);
        for (IDataSet<?> set : pieChart.getData().getDataSets()) {
            set.setDrawValues(false);
        }

        pieChart.invalidate();
    }

    private void setPieDataCk(IndexFragmentBean.CkBean ckBeanList) {

        ArrayList<PieEntry> entries = new ArrayList<PieEntry>();

        // NOTE: The order of the entries when being added to the entries array determines their position around the center of
        // the chart.

        entries.add(new PieEntry((float) (Integer.valueOf(ckBeanList.getCk_hp().getNum())),
                mParties[0],
                getResources().getDrawable(R.drawable.star)));

//        entries.add(new PieEntry((float) (Integer.valueOf(ckBeanList.getCk_zp().getNum())),
//                mParties[1],
//                getResources().getDrawable(R.drawable.star)));
//
//        entries.add(new PieEntry((float) (Integer.valueOf(ckBeanList.getCk_cp().getNum())),
//                mParties[2],
//                getResources().getDrawable(R.drawable.star)));


        if (Integer.valueOf(Integer.valueOf(ckBeanList.getCk_zp().getNum())) == 0) {
            entries.add(new PieEntry((float) (0),
                    mParties[1],
                    getResources().getDrawable(R.drawable.star)));
        }

        if (Integer.valueOf(Integer.valueOf(ckBeanList.getCk_zp().getNum())) < 100 &&
                Integer.valueOf(Integer.valueOf(ckBeanList.getCk_zp().getNum())) > 0) {
            entries.add(new PieEntry((float) (100),
                    mParties[1],
                    getResources().getDrawable(R.drawable.star)));
        }


        if (Integer.valueOf(Integer.valueOf(ckBeanList.getCk_zp().getNum())) >= 100) {
            entries.add(new PieEntry((float) (Integer.valueOf(ckBeanList.getCk_zp().getNum())),
                    mParties[1],
                    getResources().getDrawable(R.drawable.star)));
        }

        if (Integer.valueOf(Integer.valueOf(ckBeanList.getCk_cp().getNum())) == 0) {
            entries.add(new PieEntry((float) (0),
                    mParties[2],
                    getResources().getDrawable(R.drawable.star)));
        }

        if (Integer.valueOf(Integer.valueOf(ckBeanList.getCk_cp().getNum())) < 100
                && Integer.valueOf(ckBeanList.getCk_cp().getNum()) > 0) {
            entries.add(new PieEntry((float) (100),
                    mParties[2],
                    getResources().getDrawable(R.drawable.star)));
        }

        if (Integer.valueOf(Integer.valueOf(ckBeanList.getCk_cp().getNum())) >= 100) {
            entries.add(new PieEntry((float) (Integer.valueOf(ckBeanList.getCk_cp().getNum())),
                    mParties[2],
                    getResources().getDrawable(R.drawable.star)));
        }


        PieDataSet dataSet = new PieDataSet(entries, "");

        dataSet.setDrawIcons(false);

        dataSet.setSliceSpace(3f);
        dataSet.setIconsOffset(new MPPointF(0, 40));
        dataSet.setSelectionShift(5f);

        ArrayList<Integer> colors = new ArrayList<Integer>();

        for (int c : VORDIPLOM_COLORS1)
            colors.add(c);

        dataSet.setColors(colors);
        PieData data = new PieData(dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(11f);
        data.setValueTextColor(Color.WHITE);
        pieChart.setData(data);
        pieChart.highlightValues(null);
        for (IDataSet<?> set : pieChart.getData().getDataSets()) {
            set.setDrawValues(false);
        }

        pieChart.invalidate();
    }

    private void setLineData1(List<Integer> rank) {

        ArrayList<Entry> yVals = new ArrayList<Entry>();

        for (int i = 0; i < rank.size(); i++) {
            yVals.add(new Entry(i, rank.get(i)));
        }

        LineDataSet set = new LineDataSet(yVals, "Data Set");
        set.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set.setDrawValues(false);
        set.setDrawFilled(true);
        set.setHighlightEnabled(true);//是否禁用点击高亮线
        set.setHighLightColor(Color.RED);//设置点击交点后显示交高亮线的颜色
        Drawable drawable = ContextCompat.getDrawable(this.getActivity(), R.drawable.fade_linechart);
        set.setFillDrawable(drawable);

        LineData data = new LineData(set);

        lineChart.setData(data);
        lineChart.invalidate();
        lineChart.animateY(800);
    }

    private void setLineData2(List<String> handle) {
        ArrayList<Entry> yVals = new ArrayList<Entry>();

        for (int i = 0; i < handle.size(); i++) {
            yVals.add(new Entry(i, Float.valueOf(handle.get(i)) * 100f));
        }

        LineDataSet set = new LineDataSet(yVals, "Data Set");
        set.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set.setDrawValues(false);
        set.setDrawFilled(true);
        set.setHighlightEnabled(true);//是否禁用点击高亮线
        set.setHighLightColor(Color.RED);//设置点击交点后显示交高亮线的颜色
        Drawable drawable = ContextCompat.getDrawable(this.getActivity(), R.drawable.fade_linechart);
        set.setFillDrawable(drawable);

        LineData data = new LineData(set);

        lineChart.setData(data);
        lineChart.invalidate();
        lineChart.animateY(800);
    }

    private void setLineData3(List<String> speed) {
        ArrayList<Entry> yVals = new ArrayList<Entry>();

        for (int i = 0; i < speed.size(); i++) {
            yVals.add(new Entry(i, Float.valueOf(speed.get(i)) * 100f));
        }

        LineDataSet set = new LineDataSet(yVals, "Data Set");
        set.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set.setDrawValues(false);
        set.setDrawFilled(true);
        set.setHighlightEnabled(true);//是否禁用点击高亮线
        set.setHighLightColor(Color.RED);//设置点击交点后显示交高亮线的颜色
        Drawable drawable = ContextCompat.getDrawable(this.getActivity(), R.drawable.fade_linechart);
        set.setFillDrawable(drawable);

        LineData data = new LineData(set);

        lineChart.setData(data);
        lineChart.invalidate();
        lineChart.animateY(800);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);

        locationService.stop();
        locationService.unregisterListener(mListener); //注销掉监听
    }

    private BDAbstractLocationListener mListener = new BDAbstractLocationListener() {

        @Override
        public void onReceiveLocation(BDLocation location) {
            // TODO Auto-generated method stub
            if (null != location && location.getLocType() != BDLocation.TypeServerError) {
                //经度
                double longitude = location.getLongitude();
                //纬度
                double latitude = location.getLatitude();


                String lstr = latitude + "";
                String longtr = longitude + "";
                String latitudestr = lstr.substring(0, 5);
                String longitudestr = longtr.substring(0, 6);

                Intent intent = new Intent(IndexFragment.this.getActivity(), QdActivity.class);
                intent.putExtra("latitudestr", latitudestr);
                intent.putExtra("longitudestr", longitudestr);
                startActivity(intent);

                locationService.stop();
                locationService.unregisterListener(mListener); //注销掉监听

            }
        }

    };


    @Override
    public void onResume() {
        super.onResume();
        // TODO Auto-generated method stub
        super.onStart();
        // -----------location config ------------
        locationService = ((MyAppliaction) this.getActivity().getApplication()).locationService;
        //获取locationservice实例，建议应用中只初始化1个location实例，然后使用，可以参考其他示例的activity，都是通过此种方式获取locationservice实例的
        locationService.registerListener(mListener);
        //注册监听

        locationService.setLocationOption(locationService.getDefaultLocationClientOption());

    }


    @Override
    public void onClick(View v) {
        TextView textView = v.findViewById(R.id.tv);

        Intent intent = new Intent(this.getActivity(), XzsxListActivity.class);
        intent.putExtra("title", textView.getText().toString());
        startActivity(intent);
    }
}
